Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve isSocketClosingOrClosed Check to Handle WebSocket.CONNECTING State #83

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

shahzaib-deriv
Copy link
Contributor

Description:

In the current implementation of the isSocketClosingOrClosed method, the state of the WebSocket connection is checked using the following logic:

isSocketClosingOrClosed() {
    return ![2, 3].includes(this.websocket.readyState);
}

This condition currently checks if the WebSocket connection is in the CLOSED (3) or CLOSING (2) states but does not handle the CONNECTING (0) state. As a result, if send is called while the WebSocket is still in the CONNECTING state, it may throw an error.

Suggested Improvement:

To enhance robustness, updating the condition to explicitly account for the CONNECTING state as follows:

isSocketReadyForSending() {
    return this.websocket.readyState === WebSocket.OPEN; // 1
}

This modification would prevent sending messages when the WebSocket is not fully open, reducing the likelihood of encountering runtime errors and improving the overall stability of the application.

Copy link
Collaborator

@yashim-deriv yashim-deriv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit on naming. the rest lgtm

src/client-library/deriv-api-client.ts Outdated Show resolved Hide resolved
src/client-library/deriv-api-client.ts Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants